package logic

import (
	"common/model"
	"context"
	"opd_server/proto/opd"
)

func (o OpdService) DoctorList(ctx context.Context, req *opd.DoctorListRequest) (resp *opd.DoctorListResponse, err error) {
	var doctor model.Doctors
	list, err := doctor.ByList()
	if err != nil {
		return nil, err
	}
	var doctorsList []*opd.DoctorInfo
	for _, doctors := range list {
		workTime := doctors.StartWorkDate.Format("2006-01-02")
		doctorsList = append(doctorsList, &opd.DoctorInfo{
			DoctorName:          doctors.DoctorName,
			DoctorAge:           doctors.DoctorAge,
			DoctorSex:           int64(doctors.Sex),
			EducationDegree:     doctors.EducationDegree,
			StartWorkDate:       workTime,
			GraduatedUniversity: doctors.GraduatedUniversity,
			DoctorTitle:         doctors.Title,
			Department:          doctors.Department,
		})
	}
	return &opd.DoctorListResponse{
		DoctorList: doctorsList,
	}, nil
}
